#include <stdio.h>

// 最大行数
const int max_w=16;
//最大列数
const int max_h=30;
const int maxNum=30;

int searchIndex(int* array,int start,int end,int value)
{
    for(int i=start;i<end;i++)
    {
        if(array[i]==value)
        {
            return i;
        }
    }
}

void printArray(int tree[max_h][max_w])
{
    for(int i=0;i<max_h;i++)
    {
        for(int j=0;j<max_w;j++)
        {
            printf("%d ",tree[i][j]);
            
        }
        printf("\n");
    }
	printf("\n");
}


int main(){
    //用二维数组模拟二叉树
    int tree[max_h][max_w];

    int n;
    int *array1,*array2;
    scanf("%d",&n);
    array1=new int[n];
    array2=new int[n];
    int i,j;
    for(j=0;j<max_h;j++)
    {
        for(i=0;i<max_w;i++)
        {
            tree[j][i]=0;
        }
    }

    for(i=0;i<n;i++)
    {
        scanf("%d",&array1[i]);
    }
    for(i=0;i<n;i++)
    {
        scanf("%d",&array2[i]);
    }

    int queue[maxNum][4];
    int start=0,end=1;
    tree[0][0]=array1[0];
    queue[0][0]=0;
    queue[0][1]=0;
    queue[0][2]=0;
    queue[0][3]=n;

     //还原二叉树
    i=1;
    while (start<end)
    {
        int x=queue[start][0];
        int y=queue[start][1];
        int nowSt=queue[start][2];
        int nowEnd=queue[start][3];
        if(nowSt<nowEnd)
        {
            int index=searchIndex(array2,nowSt,nowEnd,tree[y][x]);
            if(nowSt<index)
            {
                int newx=x*2;
                int newy=y+1;
                tree[newy][newx]=array1[i];
                i++;
               
                queue[end][0]=newx;
                queue[end][1]=newy;
                queue[end][2]=nowSt;
                queue[end][3]=index;
                end++;
            }

            if(index<nowEnd-1)
            {
                int newx=x*2+1;
                int newy=y+1;
                tree[newy][newx]=array1[i];
                i++;
               
                queue[end][0]=newx;
                queue[end][1]=newy;
                queue[end][2]=index+1;
                queue[end][3]=nowEnd;
                end++;
            }
            
        }
        start++;

        printArray(tree);
    }

    return 0;
}